<%-- 
    Document   : createStock
    Created on : Sep 6, 2011, 12:57:07 PM
    Author     : Mikeno
--%>
<%@page import="java.util.*,hyper.market.beans.*,java.io.*"%>
<%@page contentType="text/html"%>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">

<jsp:useBean id="storeList" class="java.util.ArrayList" scope="session"/>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Create Stock</title>
        <script src="scripts/validation.js"></script>
        <link rel="stylesheet" href="style/960.css" type="text/css" />
        <link rel="stylesheet" href="style/960_12_col.css" type="text/css" />
        <link rel="stylesheet" href="style/calendarview.css" type="text/css" />
        <script src="scripts/jquery.min.js"></script>
        <link rel="stylesheet" href="desk.css" type="text/css" />
        <script type = "text/javascript">


            function initRequest() {
                if (window.XMLHttpRequest) {
                    return new XMLHttpRequest();
                } else if (window.ActiveXObject) {
                    isIE = true;
                    return new ActiveXObject("Microsoft.XMLHTTP");
                }
            }

            function uploadFile() {
                var url = "/HyperMarket/ImageUploadServlet";
                var req = initRequest();
                req.onreadystatechange = function() {   
                    if (req.readyState == 4) {
                        if (req.status == 200) {      
                            parseMessages(req.responseXML);
                        }
                    }
                };

                req.open("GET", url, true);
                req.send(null);
            }
            


            function parseMessages(responseXML) {
                var verifier = responseXML.getElementsByTagName("message")[0];
                var verifierValue = verifier.childNodes[0].nodeValue;
                if(verifierValue == 'done'){

                    var path = document.getElementById("txtFile").value;
                    var filename = getNameFromPath(path);
                    document.getElementById("imageNameH").value =  filename;
                    document.getElementById("imagedisplay").setAttribute("src", "./product/"+filename);
                    document.getElementById("imagedisplay").style.display = 'block';
                }else{
                    window.setTimeout(uploadFile(), 1000);
                }
            }

            function getNameFromPath(strFilepath) {
                var re = /\..+$/;
                var ext = (strFilepath).match(re);
                var objRE = new RegExp(/([^\/\\]+)$/);
                var strName = objRE.exec(strFilepath);

                if (strName == null) {
                    return null;
                }
                else {
                    return strName[0];
                }
            }
        </script>

        <script type="text/javascript">
            $(document).ready(function(){
                $("#loader").bind("ajaxSend", function() {
                    $(this).show();
                }).bind("ajaxStop", function() {
                    $(this).hide();
                }).bind("ajaxError", function() {
                    $(this).hide();
                });
            });
        </script>
        <!-- for calendar -->
        <script src="scripts/prototype.js"></script>
        <script src="scripts/calendarview.js"></script>
        <script>
            function setupCalendars() {

                // Popup Calendar
                Calendar.setup(
                {
                    dateField: 'expiry',
                    triggerElement: 'expiry'
                }
            )
            }

            Event.observe(window, 'load', function() { setupCalendars() })
        </script>
    </head>
    <body>

        <div class="header group">
            <div class="pagewidth">
                <ul class="headernav">
                    <li><a href="/HyperMarket/ViewStoresServlet"><img class="headerlogo" src="./arts/logo.png" width="106" height="22" alt="Bagcheck Home" border="0" /></a></li>
                    <li class="headerlink "><a p='header' t='home' href="/HyperMarket/ViewStoresServlet">Home</a></li>
                    <li class="headerlink "><a p='header' t='about' href="/HyperMarket/ViewStoresServlet">View All Stores</a></li>
                    <li class="headerlink headerlinkhl"><a p='header'  href="#" onclick="return false;">Create Stocks</a></li>
                    <li class="headerlink "><a p='header'  href="/HyperMarket/EndOfDayServlet">End Of Day</a></li>
                    <li class="headerlink "><a p='header'  href="/HyperMarket/LogoutServlet">Logout</a></li>

                </ul>
            </div>
        </div>
        <div id="loader" class="loader" style="display:none;">
            <img id="img-loader" src="images/ajax-loader.gif" alt="Loading"/>
        </div>

        <div class="container_12">
            <h1 class="blogh1 grid_12">Create New Stocks</h1>
            <form action ="/HyperMarket/CreationOfStockServlet" id="createstock" name="createstock" method ="post">

                <div class="grid_4">
                    <div style="float:inherit; width: auto">
                        <div style="height: 420px; background-color: #efefef; padding: 10px; padding-left: 50px; -webkit-border-radius: 12px; -moz-border-radius: 12px; margin-left: 10px">

                            <label>Item's Name</label><br>
                            <input style="height:20px" id="itemname" type="text" name="itemname" onchange="nameTimer(this)" >
                            <div style="display:block;" id="erroritemname">&nbsp;</div>
                            <label>Set Threshold :</label><br>
                            <input style="height:20px" type="text" id="threshold" onchange="intTimer(this)" name="threshold"><br>
                            <div style="display:block;" id ="errorthreshold">&nbsp;</div>
                            <label>Cost Price : $  </label><br>
                            <input style="height:20px" type="text" id="cost"  onchange="priceTimer(this)" name="cost"><br>
                            <div style="display:block;" id ="errorcost">&nbsp;</div>


                            <label>Usual Selling Price : $</label>
                            <input style="display:block;height:20px"  type="text" onchange="priceTimer(this)" id="selling" name="selling">
                            <div style="display:block;" id ="errorselling">&nbsp;</div>

                            <label>Quantity : </label>
                            <input style="display:block;height:20px" type="text" onchange="intTimer(this)" id="quantity" name="quantity">
                            <div style="display:block;" id ="errorquantity">&nbsp;</div>

                            <label>Discount : %</label>
                            <input  style="display:block;height:20px"  type="text" onchange="discountTimer(this)" id="discount" name="discount">
                            <div style="display:block;" id ="errordiscount">&nbsp;</div>

                            <label>Expiry Date : </label>
                            <div id="popupExample">
                                <input type="text" id="expiry" class="dateField" name="expiry" value="Show Calendar">
                            </div>

                            <div style="display:block;" id ="expirydiscount">&nbsp;</div>
                        </div>
                    </div>
                </div>
                <div class="grid_4 suffix_4">

                    <div class="grid_8">&nbsp;
                    </div>
                    <div style="float: left; width: auto; margin-top: 300px;" id="storelistdisplay">
                        <div style="height: auto; background-color: #efefef; padding: 10px; -webkit-border-radius: 12px; -moz-border-radius: 12px; margin-left: 10px">
                            <label>Select Stores that are effected by this creation</label>
                            <table cellspacing="5px">
                                <tr>
                                    <th>
                                        &nbsp;
                                    </th>
                                    <th>
                                        Stores Name
                                    </th>
                                    <th>
                                        Stores Address
                                    </th>
                                    <th>
                                        Stores Telephone
                                    </th>
                                </tr>

                                <%
                                            for (int count = 0; count < storeList.size(); count++) {
                                                out.println("<tr> <td> ");
                                                out.println("<input type=\"checkbox\" onclick=\"CountCheck("+count+")\" name=\"checkstore\" id=\"checkstore" + count + "\" value=");
                                                out.println(((StoreBean) storeList.get(count)).getStoreid());
                                                out.println("></td>");
                                                out.println("<td> " + ((StoreBean) storeList.get(count)).getStoreName() + "</td>");
                                                out.println("<td>");
                                                out.println("<p>" + ((StoreBean) storeList.get(count)).getAddress() + "</p>");
                                                out.println("</td> <td>");
                                                out.println("<p>" + ((StoreBean) storeList.get(count)).getTelephone() + "</p>");
                                                out.println("</td> </tr>");
                                            }
                                %>

                            </table>

                            <br>
                            <span id="verified" style="display:none"><font color="green">Your Ready to go!</font></span>

                            <button class=" ovaction ovactionbig ovactionprimary" style="margin: 5px 10px 0 -1px;" onclick="return submitUpdates(this.form)">Update Stock</button>

                            <input type="hidden" id="imageNameH" name="imageNameH" value="">
                            <input type="hidden" id="cbox" name="cbox" value="0">
                        </div>
                    </div>
                </div>
            </form>
                                <br>
         <div style="float: left; width: 300px; position: absolute; left: 480px; margin-top: 20px;" id="formUpload">
                <div style="height: 240px; background-color: #efefef; padding: 10px; -webkit-border-radius: 12px; -moz-border-radius: 12px; margin-left: 10px">
                    <div class="grid_4">
                        <form class="grid_4" id="upload" name="upload" enctype="multipart/form-data" method="post" target="uploadFrame"
                              action="/HyperMarket/ImageUploadServlet" >
                            <img src="./product/upload.png" class="grid_3 suffix_3" height="180" width="200" id="imagedisplay" name="imagedisplay"/>
                            <br>
                            <input type="file" name="txtFile" class="grid_6" id="txtFile" onchange="check_extension(this,'upload')"/>
                            <div style="display:none" id ="errorimage">&nbsp;</div>
                        </form>
                    </div>
                </div>
            </div>
        
        </div>
    </body>
</html>
